import { WorkflowIOValueTypeEnum } from "@/enums/WorkflowIOValueTypeEnum"
import { getWorkflowGlobalVariables } from "./utils"

export const getGlobalVariableNode = ({
    nodes,
    chatConfig
}:any) => {
    const template  = {
        id:'gloID',
        templateType:"other",
        name:'Variable',
        intro: '',
        unique: true,
        forbidDelete: true,
        version: '481',
        inputs: [],
        outputs: []
    }

    const globalVariables = getWorkflowGlobalVariables({nodes, chatConfig})

    const variableNode = {
        nodeId:'VARIABLE_NODE_ID',
        ...template,
        outputs: globalVariables.map((item) => ({
            id: item.key,
            type: 'static',
            label: item.label,
            key: item.key,
            valueType: item.valueType || WorkflowIOValueTypeEnum.any
          }))
    }

    return variableNode;
}